<?php

/**
 * 任务事件控制器 处理队列 、 任务等 .
 */
namespace Home\Controller ; 
use Think\Controller ; 
use Home\Model\UcenterModel ; 
class QueenController extends Controller {


	/**
	 * 任务一 。一秒运行一次 . 将dicusz用户合并到thinkphp
	 */

	function mergeUser(){
		$ucenter = D('Ucenter');
		$count1 = $ucenter->count(); //4
		$count2 = M('UcenterMember')->count(); //3 

		$cache_count_1 = S('ucenter_members_1');
		$cache_count_2 = S('ucenter_members_2');
		if($count1 == $count2 && ($cache_count_1 == $count1 && $cache_count_2 == $count2)){
			return  ;
		}else{
			S('ucenter_members_1', $count1);
			S('ucenter_members_2' , $count2);
			$limit = $count2 - $count1 ; 
			$limit = $limit > 0 ? $limit : -$limit; 
			$mo = M();
			$mo->execute('set autocommit=0');
		    $mo->execute('lock tables '.UCENTER_NAME.'.uc_members write,' . C('DB_NAME') . '.zw_ucenter_member write');
		    $sql = 'INSERT INTO '.C('DB_NAME').'.zw_ucenter_member (id , username , password , email , reg_ip , salt  ) SELECT ' . 
		    	    ' uid , username , password , email , regip , salt FROM ' . UCENTER_NAME . '.uc_members ORDER BY uc_members.uid desc limit 0 , ' . $limit ; 
		    	    echo $sql;
		    $res = $mo->execute($sql);
		    if($res){
				$mo->execute('commit');
				$mo->execute('unlock tables');
		    }else{
				$mo->execute('rollback');
		    }
		}

	}








}